package cs;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;

public class FileSendThread extends Thread {
    private Socket s;
    public FileSendThread(Socket s){
        this.s=s;
    }
    public static final  String FILEAME="E:/BaiduNetdiskDownload/job-salary.png";


    @Override
    public void run() {
        System.out.println(s+"连接了");
        FileInputStream fin= null;
        try {
            fin = new FileInputStream(FILEAME);
            byte[]b=new byte[fin.available()];
            int len=fin.read(b);
            fin.close();
            //读完内容,准备发送
            OutputStream out=s.getOutputStream();
            out.write(b,0,len);
            out.flush();
            System.out.println("文件发送给"+s+"成功");
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            if(s!=null&&!s.isClosed()) {
                try {
                    s.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

    }
}
